﻿using System;
using System.Collections;
using System.Windows.Forms;

namespace 系统信息
{
    public partial class 系统环境变量 : Form
    {
        public 系统环境变量()
        {
            InitializeComponent();
        }

        struct ComboBoxItem
        {
            public ComboBoxItem(string a, string b)
            {
                strText = a;
                strValue = b;
            }

            public string strText;
            public string strValue;

            public string Text
            {
                get
                {
                    return strText;
                }
                set
                {
                    strText = value;
                }
            }

            public string Value
            {
                get
                {
                    return strValue;
                }
                set
                {
                    strValue = value;
                }
            }
        }

        private void 系统环境变量_Load(object sender, EventArgs e)
        {
            IDictionary environmentVariables = System.Environment.GetEnvironmentVariables();
            ArrayList al = new ArrayList();
            //al.Add(new ComboBoxItem("", ""));

            foreach (DictionaryEntry de in environmentVariables)
            {
                ComboBoxItem cb = new ComboBoxItem();
                cb.strText = de.Key.ToString();
                cb.strValue = de.Value.ToString();

                //Console.WriteLine("  {0} = {1}", de.Key, de.Value);
                al.Add(cb);
            }

            this.comboBox1.DataSource = al;
            this.comboBox1.DisplayMember = "Text";

            //string strPath = System.Environment.GetEnvironmentVariable("Path");
            this.richTextBox1.Text = ((ComboBoxItem)(this.comboBox1.SelectedItem)).strValue;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //this.richTextBox1.Text = strPath;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.richTextBox1.Text = ((ComboBoxItem)(this.comboBox1.SelectedItem)).strValue;
        }

        /// <summary>
        /// xiu gai
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string strT = this.richTextBox1.Text;

            if (strT == "") { return; }

            System.Environment.SetEnvironmentVariable(((ComboBoxItem)(this.comboBox1.SelectedItem)).Text, strT);

            this.richTextBox1.Text = ((ComboBoxItem)(this.comboBox1.SelectedItem)).strValue;
        }
    }
}